#ifndef BUTTONMANAGER_H
#define BUTTONMANAGER_H

#include <QObject>
#include <QMap>
#include <QMutex>
#include <QWaitCondition>

class ButtonManager : public QObject
{
    Q_OBJECT
public:
    static ButtonManager* instance();

    // 用于后端获取按钮点击信息
    QMap<int, bool> getButtonStates();
    void resetButtonStates();

    // 信号连接起来
    Q_PROPERTY(quint8  rcvByte1                  READ rcvByte1                      NOTIFY rcvByte1Changed)
    Q_PROPERTY(quint8  rcvByte2                  READ rcvByte2                      NOTIFY rcvByte2Changed)

    //定义封装函数
    quint8     rcvByte1              () { return _rcvByte1; }
    quint8     rcvByte2              () { return _rcvByte2; }

signals:
    void buttonClicked(int buttonId);

    // 定义接受字符更改函数
    void rcvByte1Changed              (quint8 rcvByte1);
    void rcvByte2Changed              (quint8 rcvByte2);

public slots:
    // 在qml中调用
    void handleButtonClick(int buttonId);

private:
    ButtonManager();
    static ButtonManager* m_instance;
    static QMutex mutex; // 修改为静态成员
    QWaitCondition waitCondition;
    QMap<int, bool> buttonStates;

    // 定义接收函数
    void _handleCSDNTestRcv(int  rcv1, int rcv2);

    quint8            _rcvByte1;
    quint8            _rcvByte2;
};

#endif // BUTTONMANAGER_H
